package edu.suda.xsap.service.impl;

import edu.suda.xsap.entity.ChartData;
import edu.suda.xsap.dto.CourseDto;
import edu.suda.xsap.dto.convert.CourseConvert;
import edu.suda.xsap.entity.Course;
import edu.suda.xsap.entity.CourseCount;
import edu.suda.xsap.mapper.CourseMapper;
import edu.suda.xsap.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CourseServiceImpl implements CourseService {

    @Autowired
    private CourseMapper courseMapper;

    @Autowired
    private CourseConvert courseConvert;

    @Override
    public List<CourseDto> findAll() {
        List<Course> courses = courseMapper.findAll();
        return courseConvert.toDtoList(courses);
    }

    @Override
    public List<ChartData> getCount() {
        List<CourseCount> courseCount = courseMapper.getCount();
        return courseConvert.toCountDtoList(courseCount);
    }
}